<?php 
$trace = false;
if ( @$blazon = $_GET['blazon'] ) {
  echo "<h2>Blazon Structure</h2>\n";
  include "parser/parser.inc";
  $p = new parser('english');
  $xml = $p->parse($blazon,'dom');
  $errors = $p->getErrors('html');
  $p = null; // destroy parser
  // Resolve references
  include "analyser/references.inc";
  $references = new references($xml);
  $refErrors = '';
  $xml = $references->setIDREFs($refErros,'html');
  $references = null; // destroy references
  $errors .= $refErrors;
  // Add dictionary references
  include "analyser/addlinks.inc";
  $adder = new linkAdder($xml);
  $xml = $adder->addLinks();
  $adder = null;
  include "analyser/xmlformatter.inc";
  $formatter = new xmlformatter($xml);
  if ( isset($_GET['tokens']) )
    $formatter->setOptions('html',true);
  if ( isset($_GET['format']) ) 
    $format = $_GET['format'];
  else
    $format = 'text-c';
  switch ( $format ) {
    case 'xml-f':
       echo "<pre>\n" . htmlentities($formatter->format_xml()) . "\n</pre>\n";
      break;
    case 'text-s':
      echo $formatter->text_tree(2,1);
      break;
    default:
    case 'text-c':
      echo $formatter->text_tree(1,0);
      break;
  }
  $formatter = null; // destroy formatter
  // always report errors
  if ( $errors ) {
    echo "<h2>Reported Errors</h2>\n";
    echo $errors;
  }
  if ( isset($_GET['obsolete']) ) {
    include "analyser/obsolete.inc";
    $obsolete = new obsolete($xml);
    $obs = $obsolete->report('html');
    $obsolete = null; // destroy obsolete
    if ( $obs ) echo "<h2>Obsolete Items</h2>$obs\n";
  }
  if ( isset($_GET['complex']) ) {
    include "analyser/complexity.inc";
    $complexity = new complexity($xml);
    $comps = $complexity->report('html');
    $complexity = null; // destroy references
    if ( $comps ) echo "<h2>Complexity Report</h2>$comps\n";
  }
  if ( isset($_GET['references']) ) {
    include "analyser/references.inc";
    $references = new references($xml);
    $refs = $references->report('html');
    $references = null; // destroy references
    if ( $refs ) echo "<h2>Cross References</h2>$refs\n";
  }
}
?>
